import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from '../views/Home.vue'
import Index from '@/components/home/index/index.vue'
import Detail from '@/components/home/detail/Detail.vue'
import Business from '@/components/home/business/business.vue'
import Classification from '@/components/home/classification/classification.vue'
import Notice from '@/components/home/notice/notice.vue'
import Notticitem from '@/components/home/notice/notticitem.vue'
import Service from '@/components/home/service/service.vue'
import Guide from '@/components/home/guide/guide.vue'
import Order from '@/components/home/order/order.vue'
import Document from '@/components/home/document/document.vue'
import Documentitem from '@/components/home/document/documentitem.vue'
import Demand from '@/components/home/demand/demand.vue'
import Release from '@/components/home/demand/release.vue'
import Releaseitem from '@/components/home/demand/releaseitem.vue'
import Conindex from '@/components/home/console/console.vue'
import Yindex from '@/components/home/console/item/yindex.vue'
import Yorder from '@/components/home/console/item/order.vue'
import Invoice from '@/components/home/console/item/invoice.vue'
import Ydemand from '@/components/home/console/item/demand.vue'
import Collection from '@/components/home/console/item/collection.vue'
import News from '@/components/home/console/item/news.vue'
import Cart from '@/components/home/console/item/cart.vue'
import Address from '@/components/home/console/item/address.vue'
import Evaluate from "@/components/home/console/item/evaluate.vue"
import Approval from '@/components/home/console/item/approval.vue'
import Search from '@/components/home/search/search.vue'
import Pay from '@/components/home/pay/pay.vue'


import LoginIndex from '@/components/login/login.vue'
import IndividualUser from '@/components/login/IndividualUser.vue'
import EnterpriseUser from '@/components/login/EnterpriseUser.vue'
import Forget from '@/components/login/Forget.vue'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: { name: "home" } },  // 重定向到主页
  {
    name: 'home', path: '/home', component: Home,
    redirect: { name: "index" },
    children: [
      {
        path: 'index',//首页
        name: 'index',
        component: Index
      },
      {
        path: 'detail',//商品详情
        name: 'detail',
        component: Detail
      },
      {
        path: 'business',//店铺详情
        name: 'business',
        component: Business
      },
      {
        path: 'classification',//分类
        name: 'classification',
        component: Classification
      },
      {
        path: 'notice',//公告
        name: 'notice',
        component: Notice
      },
      {
        path: 'notticitem',//公告详情
        name: 'notticitem',
        component: Notticitem
      },
      {
        path: 'service',//支持与服务
        name: 'service',
        component: Service
      },
      {
        path: 'guide',//入驻流程
        name: 'guide',
        component: Guide
      },
      {
        path: 'order',//支付
        name: 'order',
        component: Order
      },
      {
        path: 'document',//文档
        name: 'document',
        component: Document
      },
      {
        path: 'documentitem',//文档详情
        name: 'documentitem',
        component: Documentitem
      },
      {
        path: 'demand',//需求列表
        name: 'demand',
        component: Demand
      },
      {
        path: 'release',//发布需求
        name: 'release',
        component: Release
      },
      {
        path: 'releaseitem',//需求详情
        name: 'releaseitem',
        component: Releaseitem
      },
      {
        path: 'search',//需求详情
        name: 'search',
        component: Search
      },
      {
        path: 'conindex',//用户中心
        name: 'conindex',
        component: Conindex,
        redirect: { name: "yindex" },
        children: [
          {
            path: 'yindex',//个人信息
            name: 'yindex',
            component: Yindex
          },
          {
            path: 'order',//订单管理
            name: 'yorder',
            component: Yorder
          },
          {
            path: 'invoice',//发票信息
            name: 'invoice',
            component: Invoice
          },
          {
            path: 'demand',//需求管理
            name: 'ydemand',
            component: Ydemand
          },
          {
            path: 'collection',//收藏管理
            name: 'collection',
            component: Collection
          },
          {
            path: 'news',//信息管理
            name: 'news',
            component: News
          },
          {
            path: 'cart',//购物车
            name: 'cart',
            component: Cart
          },
          {
            path: 'address',//地址管理
            name: 'address',
            component: Address
          },
          {
            path: 'evaluate',//我的评论
            name: 'evaluate',
            component: Evaluate
          },
          {
            path: 'approval',//审核订单
            name: 'approval',
            component: Approval
          },

        ]
      },

    ]
  },
  { path: '/pay', name: 'Pay', component: Pay,},
  {
    path: '/login', name: 'Login', component: () => import('../views/login.vue'),
    redirect: { name: "loginindex" },
    children: [
      {
        path: 'loginindex',
        name: 'loginindex',
        component: LoginIndex
      },
      {
        path: 'individualUser',
        name: 'individualUser',
        component: IndividualUser
      },
      {
        path: 'enterpriseUser',
        name: 'enterpriseUser',
        component: EnterpriseUser
      },
      {
        path: 'forget',
        name: 'forget',
        component: Forget
      },

    ]
  },
  { path: '/settlein', name: 'SettleIn', component: () => import('../views/SettleIn.vue') },
]

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  // 让页面回到顶部
  document.documentElement.scrollTop = 0
  // 调用 next()，一定要调用 next 方法，否则钩子就不会被销毁
  next()
})
export default router
